<template>
	<view :class="[config.style]">
		<!-- #ifdef H5-->
		<Top :config="config"></Top>
		<!-- #endif -->
		<!--数据列表部分-->
		<view class="list-section uni-clearfix">
			<!-- top="xxx"下拉布局往下偏移,防止被悬浮菜单遮住 -->
			<mescroll-uni ref="mescrollRef" @init="mescrollInit" :top="top" :down="downOption" @down="downCallback" @up="upCallback">
				<!-- 数据列表 -->
				<view class="list">
					<view class="item" v-for="(item,index) in list" :key="index" @click="goToTeacherDetailLink(item.teacher_info.id)">
						<view class="content">
							<view class="cover">
								<image mode="widthFix" :src="item.teacher_info.cover_200" class="image"></image>
							</view>
							<view class="info">
								<view class="title text-ellipsis">{{item.teacher_info.name}}</view>
								<view class="description text-ellipsis-2">{{item.teacher_info.description}}</view>
							</view>
						</view>
					</view>
				</view>
			</mescroll-uni>
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import Top from '../../common/top.vue'

	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		components: {
			Top
		},
		data() {
			return {
				urlParams: {}, //url传递过来的参数
				page: 1, //当前页码
				list: [], //列表数据
				top: 72,
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption:{
					// page: {
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty:{
						tip: '~ 搜索无数据 ~', // 提示
						btnText: '去看看'
					}
				},
			}
		},
		onLoad(option) {
			//获取url参数
			this.urlParams = option
		},
		created() {
			//#ifdef MP-WEIXIN
			this.top = 0
			//#endif
			//#ifdef H5
			this.top = 72
			//#endif
		},
		computed: {
			...mapState(['config'])
		},
		methods: {

			//上拉加载的回调
			upCallback: function() {
				let that = this
				let data = this.urlParams
					data.action = 'lists'
					data.m = 'muu_classroom'
					data.page = this.page
				//获取数据
				let url = '';
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/follow'
					//#endif
					//#ifdef H5
					url = 'entry/site/follow'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							let list = res.data.data.data
							that.list = that.list.concat(list);
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							that.mescroll.endSuccess(list.length);
							that.page = that.page + 1
						}
					}
				})
			},
			//下拉刷新
			downCallback: function() {
				let that = this
				this.page = 1
				let data = this.urlParams
					data.action = 'lists'
					data.m = 'muu_classroom'
					data.page = this.page
				//获取分页列表首页数据
				let url = '';
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/follow'
					//#endif
					//#ifdef H5
					url = 'entry/site/follow'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							that.list = []
							that.list = res.data.data.data
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							that.mescroll.endSuccess(that.list.length);
							that.page = 2
						}
					}
				})
			},
			//点击空布局按钮的回调
			emptyClick(){
				uni.showToast({
					title:'点击了按钮,具体逻辑自行实现'
				})
			},
			
			//路由至详情页
			goToTeacherDetailLink: function(id){
				let urlParams = 'id='+id
				let url = '../../teacher/detail?' + urlParams
				console.log(url)
				//指定跳转地址
				uni.navigateTo({
				    url: url
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #f8f8f8;
		min-height: 100%;
		height: auto;
	}
	
	/*竖排*/
	.list {
		/*小图*/
		display: flex;
		flex-wrap: wrap;
		.item {
			width: 100%;
			.content {
				margin: 10rpx 20rpx;
				display: flex;
				flex-wrap: wrap;
				background-color: #fff;
				border-radius: 10rpx;
				overflow: hidden;
				.cover {
					width: 280rpx;
					border-radius: 10rpx 0 0 10rpx;
					overflow: hidden;
					.image {
						width: 100%;
						height: auto;
						display: block;
					}
				}
				.info {
					padding: 20rpx;
					flex: 1;
					.title {
						font-size: 28rpx;
						color: #000;
						font-weight: 600;
						height: 72rpx;
						line-height: 36rpx;
					}
					.description {
						color: #999;
						font-size: 24rpx;
					}
					.price {
						margin-top: 10rpx;
						font-size: 24rpx;
					}
					.exp-info {
						margin-top: 10rpx;
						color: #999;
						font-size: 24rpx;
						.item {
							display: inline;
							.num {
								margin: 0 10rpx;
							}
						}
					}
				}
			}
		}
	}
	
	/*页面风格设计*/
	.Blue {
		
	}
</style>
